package org.shop.pro.config.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.shop.pro.entity.Shop;
import org.shop.pro.entity.Shopgoods;
import org.shop.pro.entity.Types;
import org.shop.pro.service.ShopService;
import org.shop.pro.service.TypesService;
import org.shop.pro.service.shopgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class shopgoodsController {
	
	@Autowired
	ShopService shop;
	@Autowired 
	TypesService types;
	@Autowired
	shopgoodsService shopgoods;
	@RequestMapping("/toshopinfo")
	public String toshopinfo(int shopid,Model model,HttpSession session,HttpServletRequest request) {
	 int vid=(int)session.getAttribute("id");
	 List<Shopgoods> cartlist=shopgoods.cartlist(vid, shopid);
	 
	  
	   Shop shopinfo=shop.selectByPrimaryKey(shopid);
	   List<Types> typesname=types.typenamelist(shopid);
	   model.addAttribute("typeslist", typesname);
	   model.addAttribute("shopinfo",shopinfo);
	   model.addAttribute("cartlist", cartlist);
		return "shopgoodsinfo";
	}
	
	@ResponseBody
	@RequestMapping("/togoodslist")
	public List<Shopgoods> togoodslist(int typeid,int shopid,Model mdoel){
		List<Shopgoods> goodslist=shopgoods.goodslistss(shopid, typeid);

		return goodslist;
	}
	
	@RequestMapping("/tocar")
	public String tocar(Model model,HttpSession session) {
int vid=(int) session.getAttribute("id");
List<Shop> cartshopname=shop.cartshoplist(vid);
List<Shopgoods> cartgoodsname=shopgoods.cartgoods(vid);
model.addAttribute("cartshoplist", cartshopname);
model.addAttribute("cartgoodsname", cartgoodsname);
		return "car";
	}
}
